﻿@{
    Layout = null;
}
@model Freshbox2._0.MODEL.store
<!DOCTYPE html>

<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <meta name="viewport" content="width=device-width" />
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>
    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>

    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <title></title>
    <script type="text/javascript">
        $(function () {
            $("#data").datagrid({
                fit: true,
                title: '后台管理人员信息列表',
                striped: true,
                rownumbers: true,
                columns:
                    [[{
                        field: 'ck',
                        checkbox: true
                    }, {
                        field: 'storeid',
                        title: '编号',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        sortable: true,
                        align: 'center'
                    }, {
                        field: 'storeName',
                        title: '用户名',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'adminPassword',
                        title: '密码',
                        width: 300,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'name',
                        title: '角色',
                        width: 300,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'state',
                        title: '状态',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }]],
                url: pageConfig.getAction,
                pagination: true,
                pageSize: 10,
                pageList: [10, 15, 20, 25],
                sortName: 'adminId',
                sortOrder: 'desc',
                toolbar: '#tool'
            });

            $("#formdialog").dialog({
                width: 400,
                height: 250,
                closed: true,
                modal: true,
                buttons: '#btns'
            });

        });
        var pageConfig = {
            type: null,
            getAction: '@Url.Action("GetOrderDatas")',
            saveAction: '@Url.Action("Save")',
            delAction: '@Url.Action("ModifyState")',
            modifyAction: '@Url.Action("Modify")',
            getOneAction: '@Url.Action("GetOnlyOne")',
        };
        ///禁用用户   状态改变
        function del() {

            var rows = $("#data").datagrid("getSelections")
            if (rows.length <= 0) {
                $.messager.alert("禁用用户", "没有选中的行", "info");
                return;
            }

            $.messager.confirm("确定操作", "您确定要禁用该用户吗？", function (flag) {
                if (flag) {
                    var idsStr = rows[0].adminId;
                    $.ajax({
                        url: pageConfig.delAction,
                        data: { id: idsStr },
                        dataType: "json",
                        type: "POST",
                        beforeSend: function () {
                            before();
                        },
                        success: function (data) {
                            success(data);
                        },
                        error: function () {
                            error();
                        },
                        complete: function () {
                            complete();
                        }
                    });
                }
            })
        }
        //弹出框
        function alertFormDialog(type) {
            pageConfig.type = type;
            $("#formdialog form").form("reset");
            if (type == 1) {
                $("#formdialog").dialog("open");
                $("#formdialog").dialog("setTitle", "添加");
                $("#formdialog form").attr("action", pageConfig.saveAction);
            }
            else {
                var rows = $("#data").datagrid("getSelections");

                if (rows.length != 1) {
                    $.messager.alert("提示", "修改时必须且只能选中一条记录！", "info");
                }
                if (rows[0].state == 1) {
                    $.messager.alert("提示", "此用户已经被禁用！不能进行修改", "info");
                }
                else {

                    $("#formdialog").dialog("open");
                    $("#formdialog").dialog("setTitle", "修改");
                    $('#adminUsername').attr("disabled", true);//不可编辑
                    $.ajax({
                        async: false,
                        url: pageConfig.getOneAction + "?id=" + rows[0].adminId,
                        dataType: "json",
                        type: "POST",
                        success: function (data) {
                            //alert(data.name);
                            $("#formdialog input[name='adminId']").val(data.adminId);
                            $("#adminUsername").val(data.adminUsername);
                            $("#adminPassword").val(data.adminPassword);
                            $("#name").combobox('setValue', data.name);
                            $("#name").combobox('setValue', data.authoritys);
                        }
                    });
                }
            }
        }

        function closeDptDialog() {
            $("#formdialog").dialog("close")
        }
        //点击保存按钮   
        function save() {
            var a = $("#adminUsername").val();
            //alert(a);   //可以获取到
            if ($("#adminUsername").val() != null && $("#adminUsername").val() != "" && $("#adminPassword").val() != null && $("#adminPassword").val() != "") {
                var bool = $("#fm").form("validate");
                if (bool) {
                    var rows = $("#data").datagrid("getSelections");
                    var data;
                    if (pageConfig.type == 1) {
                        url = pageConfig.saveAction;
                        data = {
                            adminId: $("#formdialog input[name='adminId']").val(),
                            adminUsername: $("#adminUsername").val(),
                            adminPassword: $("#adminPassword").val(),
                            authoritys: $("#name").combobox('getValue'),
                            name: $("#name").combobox('getText')


                        };
                    }
                    else {
                        url = pageConfig.modifyAction;
                        data = {
                            adminId: $("#formdialog input[name='adminId']").val(),
                            adminUsername: $("#adminUsername").val(),
                            adminPassword: $("#adminPassword").val(),
                            authoritys: $("#name").combobox('getValue'),
                            name: $("#name").combobox('getText')
                        };
                    }
                    $.ajax({
                        url: url,
                        dataType: "json",
                        data: data,
                        type: "POST",
                        beforeSend: function () {
                            $.messager.progress({ title: "执行中", text: "" });
                        },
                        success: function (data) {
                            $.messager.alert("成功", data.msg, "info");
                        },
                        error: function (data) {
                            $.messager.alert("警告", "系统故障", "error", "")
                        },
                        complete: function () {

                            complete();
                        }
                    });

                }
            }
            else {
                $.messager.alert("用户名和密码不能为空", "用户名和密码不能为空", "info");
            }
        }

        function searchData() {
            $("#data").datagrid('load', {
                adminUsername: $("#txtName").val()

            });
        }

        function before() {
            $.messager.progress({ title: "执行中", text: "" });
        }

        function success(data) {
            $.messager.alert("成功", data.msg, "info");
        }
        function error() {

            $.messager.alert("警告", "系统故障", "error", "")
        }

        function complete() {
            $("#data").datagrid("load");
            $.messager.progress("close");
            $("#formdialog").dialog("close");
        }
        function ExportWord() {
            window.location.href = "/WordTest/ExportWord";
        }
    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'">
        <table id="data"></table>
        <div id="tool" style="padding: 10px;">
            <div style="margin-bottom: 10px;">
                <div style="margin-bottom: 10px;">
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" iconcls="icon-add" style="width: 100px; height: 50px;" onclick="alertFormDialog(1)">添加人员</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" iconcls="icon-edit" style="width: 100px; height: 50px;" onclick="alertFormDialog(2)">修改密码</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" iconcls="icon-remove" style="width: 100px; height: 50px;" onclick="del()">禁用用户</a>
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                用户名：<input id="txtName" style="width: 180px; height: 25px; margin-top: 15px" type="text" oninput="searchData()" />
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                <a class="easyui-linkbutton" iconcls="icon-search" onclick="searchData()">查询</a>
                </div>
            </div>
        </div>
    </div>

    <div id="formdialog">
        @using (Ajax.BeginForm(new AjaxOptions
        {
            OnBegin = "before",
            OnComplete = "complete",
            OnSuccess = "success",
            OnFailure = "error",
            HttpMethod = "Post"
        }))
        {
            <div class="dialog-table">
                <form id="fm" method="post">

                    @Html.HiddenFor(x => x.storeid)

                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tk_table">

                        <tr>
                            <td>用户名：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="adminUsername" data-options="required:true" /></td>

                        </tr>
                        <tr>
                            <td>密码：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" type="password" id="adminPassword" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>角色：</td>
                            <td class="white-tr">
                                <select class="easyui-combobox" id="name" name="name" style="width: 150px">
                                    <option value="1">超级管理员</option>
                                    <option value="2">管理员</option>
                                    <option value="0">后台统计管理</option>
                                    <option value="3">商品管理员</option>
                                    <option value="4">会员管理</option>
                                    
                                </select>
                        </tr>
                    </table>
                </form>
            </div>
        }
    </div>

    <div id="btns">
        <div style="margin-bottom: 10px">
            <a class="easyui-linkbutton" iconcls="icon-redo" onclick="closeDptDialog()">取消</a>
            <a class="easyui-linkbutton" iconcls="icon-add" onclick="save()">保存</a>
        </div>
    </div>

</body>
</html>
